package com.wanma.recuit.bosscontroller;

import com.wanma.recuit.pojo.CompanyUser;
import com.wanma.recuit.pojo.Dictionary;
import com.wanma.recuit.pojo.Industry;
import com.wanma.recuit.pojo.Job;
import com.wanma.recuit.service.CreatPositionService;
import com.wanma.recuit.service.DictionaryService;
import com.wanma.recuit.service.IndustryService;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class CreatPositionController {
    @Resource
    private CreatPositionService creatPositionService;

    @Resource
    private IndustryService industryService;
    @Resource
    private DictionaryService dictionaryService;

    @RequestMapping("bossmanage/create")
    public ModelAndView index()
    {
        ModelAndView modelAndView=new ModelAndView();
        List<Industry> industries=industryService.findAll();
        Dictionary education=dictionaryService.findEducation();

        Dictionary experience=dictionaryService.findExperience();


        Dictionary charactorkind=dictionaryService.findKind();
        Dictionary salary=dictionaryService.findSalary();
        modelAndView.addObject("education",education);
        modelAndView.addObject("experience",experience);
        modelAndView.addObject("charactorkind",charactorkind);
        modelAndView.addObject("salary",salary);
        modelAndView.addObject("industries",industries);

        return modelAndView;
    }
    @RequestMapping("/bossmanage/insert")
    public ModelAndView insert(HttpServletRequest request,Integer ppp, String positionName, Integer cha, Integer salary, String address, Integer exp, Integer edu, String introduce, String positionAddress)
    {
        System.out.println("11111111");
        ModelAndView modelAndView=new ModelAndView();
        HttpSession session=request.getSession();
        CompanyUser companyUser =(CompanyUser) session.getAttribute("companyUser");
        Job job =new Job();
        job.setCompanyId(companyUser.getCompanyId());
        job.setCompanyUserId(companyUser.getId());
        job.setCharacterId(cha);
        job.setPositionId(ppp);
        job.setJobName(positionName);
        job.setSalaryId(salary);
        job.setJobAdress(address);
        job.setEducationId(edu);
        job.setExperienceId(exp);
        job.setJobIntroduce(introduce);
        job.setPositionaddress(positionAddress);
        creatPositionService.insert(job);
        modelAndView.setViewName("redirect:/bossmanage/index06");
        System.out.println("11111111");
        return modelAndView;
    }

    @RequestMapping("/bossmanage/index06")
    public void creatsuccess(){

    }
}
